<template>
	<view class="main">
		<tou_hand1 handtitle='确认订单'></tou_hand1>
		<view class="show">
			<view class="one" v-show="type==1" v-for="(item, index) in listdetail" :key="index">
				<view class="onefirst">设备编号：{{item.code}}</view>
				<view class="onesecond">端口数量：<span>{{item.portsNum}}个</span></view>
				<view class="onesecond">设备位置：<span>{{item.projectName}}-{{item.areaName}}</span></view>
			</view>
			<view class="one" v-show="type==2" v-for="(item, index) in listdetail" :key="index+item.id">
				<view class="onefirst">设备编号：{{item.code}}</view>
				<view class="onesecond">端口数量：<span>{{item.portsNum}}个</span></view>
				<view class="onesecond">保单号：
					<span v-if="item.insureOrder">{{item.insureOrder}}</span>
					<span v-else style="color: #4B98ED;">生成中</span>
				</view>
				<view class="onesecond">保单开始时间：
					<span v-if="item.insureStartTime">{{item.insureStartTime}}</span>
					<span v-else>-</span>
				</view>
				<view class="onesecond">保单结束时间：
					<span v-if="item.insureEndTime">{{item.insureEndTime}}</span>
					<span v-else>-</span>
				</view>
				<view class="onesecond">设备位置：<span>{{item.projectName}}-{{item.areaName}}</span></view>
			</view>
			<view class="two">
				<view class="twoshang">总共{{list.deviceNum}}台设备，{{list.portsNum}}个端口</view>
				<view class="twoxia">
					<view class="twoxialeft">购买期限:{{list.expireData}}年</view>
					<view class="twoxiaright">
						<view class="twoxiarighttxt">合计：<span style="font-size: 32upx;">¥{{(list.orderMoney).toFixed(2)}}</span></view>
						<view class="twoxiarightmap" @click="buybtn(list.orderNo)">提交订单</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tou_hand1 from '../../components/tou_hand1/tou_hand1.vue'
	// import wx from "../../common/jweixin-module/index.js"
	// import {
	// 	Config
	// } from "../../common/Config.js"
	// import {
	// 	Dialog
	// } from 'vant';
	export default {
		components: {tou_hand1},
		mounted() {
			
		},

		data() {
			return {
				type:1,
				orderNo:'',
				list:'',
				listdetail:''
			}
		},
		onLoad(option) {
			this.type=option.type
			this.orderNo=option.orderNo
			this.show()
		},
		methods: {
			show(){
				let data={
					orderNo:this.orderNo
				}
				this.$base.request1('manager/site/order/getCacheByOrderNo', 'GET', data)
				.then(res => {
					if(res.data.code==200){
						this.list=res.data.data.siteDeviceOrder
						this.listdetail=res.data.data.siteDeviceDetails
					}else{
						this.$toast.fail(res.data.msg)
					}
				})
				.catch(err => {
					
				})
			},
			buybtn(orderNo){
				let data={
					orderNo:orderNo
				}
				uni.showLoading({
					title: '请稍候',
					mask: true
				})
				this.$base.request('order/siteOrderPay', 'POST', data)
				.then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						let arr = res.data.data
						let _this = this
					
						function onBridgeReady() {
							WeixinJSBridge.invoke(
								'getBrandWCPayRequest', {
									"appId": arr.appId, //公众号名称，由商户传入
									"timeStamp": arr.timeStamp, //时间戳，自1970年以来的秒数     
									"nonceStr": arr.nonceStr, //随机串     
									"package": arr.wpackage,
									"signType": arr.signType, //微信签名方式：     
									"paySign": arr.paySign //微信签名 
								},
								function(res) {
									if (res.err_msg == "get_brand_wcpay_request:ok") {
										_this.$toast.success('购买成功')
										uni.navigateBack()
										// if(_this.powerontype==1){
										// 	uni.navigateBack()
										// }else{
										// 	uni.redirectTo({
										// 		url: '../index/index'
										// 	})
										// }
										
										// setTimeout(() => {
										// 	_this.$refs.mainindex.userdetail();
										// }, 2000)
										// 使用以上方式判断前端返回,微信团队郑重提示：
										//res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
									} else {
										uni.navigateBack()
										// if(_this.powerontype==1){
										// 	uni.navigateBack()
										// }else{
										// 	uni.redirectTo({
										// 		url: '../index/index'
										// 	})
										// }
									}
								});
						}
						if (typeof WeixinJSBridge == "undefined") {
							if (document.addEventListener) {
								document.addEventListener('WeixinJSBridgeReady', onBridgeReady,
									false);
							} else if (document.attachEvent) {
								document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
								document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
							}
						} else {
							onBridgeReady();
						}
					} else {
						this.$toast.fail(res.data.msg)
					}
				})
				.catch(err => {
					
				})
			}
			
		}
	}
</script>
<style>
	
	page{
		 background-color: #EAE9E9 !important;
	}
</style>
<style lang="scss" scoped>
	.main {
		width: 100%;
		.show{
			width: 100%;
			box-sizing: border-box;
			padding: 27upx 18upx;
			padding-bottom:200upx;
			.one{
				width: 100%;
				box-sizing: border-box;
				padding: 25upx 55upx;
				background-color: #fff;
				border-radius: 10upx;
				margin-bottom: 15upx;
				box-sizing: border-box;
				.onefirst{
					font-size: 32upx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					color: #4B98ED;
					line-height: 38upx;
					margin-bottom: 17upx;
				}
				.onesecond{
					font-size: 26upx;
					font-family: PingFang-SC-Regular-, PingFang-SC-Regular;
					font-weight: normal;
					color: #999999;
					line-height: 31upx;
					margin-bottom: 10upx;
					span{
						color: #666;
					}
				}
			}
			.two{
				width: 100%;
				position: fixed;
				left: 0upx;
				bottom: 0upx;
				.twoshang{
					width: 100%;
					padding: 15upx 37upx;
					box-sizing: border-box;
					background-color: #EFE2B3;
					font-size: 28upx;
					font-family: PingFang-SC-Regular-, PingFang-SC-Regular;
					font-weight: normal;
					color: #F67004;
					line-height: 34upx;
				}
				.twoxia{
					width: 100%;
					box-sizing: border-box;
					background-color: #fff;
					padding: 33upx 29upx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					.twoxialeft{
						font-size: 28upx;
						font-family: PingFang-SC-Regular-, PingFang-SC-Regular;
						font-weight: normal;
						color: #010101;
						line-height: 34upx;
					}
					.twoxiaright{
						display: flex;
						align-items: center;
						.twoxiarighttxt{
							font-size: 20upx;
							font-family: PingFang-SC-Regular-, PingFang-SC-Regular;
							font-weight: normal;
							color: #010101;
							line-height: 34upx;
							span{
								color:#E92600 ;
							}
						}
						.twoxiarightmap{
							width: 112upx;
							background: #0083FF;
							border-radius: 10upx;
							text-align: center;
							font-size: 24upx;
							font-family: Yu Gothic UI-Regular, Yu Gothic UI;
							font-weight: 400;
							color: #FFFFFF;
							padding: 10upx 0;
							margin-left: 20upx;
						}
					}
				}
			}
		}
	}
</style>
